#include<bits/stdc++.h>
//#define int long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=1e6+5,base=999983,Mod=998244353;
//char buf[(1<<21)+5],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void chmx(int &x,int y){(x<y)&&(x=y);}
inline void chmn(int &x,int y){(x>y)&&(x=y);}
inline void Add(int &x,int y){(x=x+y+Mod)%=Mod;}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
void print(int n){
    if(n<0){
        putchar('-');
        n*=-1;
    }
    if(n>9) print(n/10);
    putchar(n%10+'0');
}
int n;
int fa[N][21];
int in[N];
vector<int>q[N];
int dfn[N],cnt,id[N],dep[N];
int qu[N],idx;
int dfna[N];
void dfs(int u,int pa){
	id[++cnt]=u;
	dfn[u]=cnt;
	dfna[u]=++idx,qu[idx]=u;
	dep[u]=dep[pa]+1;
	For(i,1,20) fa[u][i]=fa[fa[u][i-1]][i-1];
	for(auto v:q[u]){
		dfs(v,u);
		qu[++idx]=u;
	}
}
int st[N][21]; 
int lg[N];
void buildst(){
	For(i,1,idx)st[i][0]=qu[i];
	For(j,1,20)
		for(int i=1;i+(1<<j)<=idx;++i){
			int f1=st[i][j-1],f2=st[i+(1<<j-1)][j-1];
			st[i][j]=dep[f1]<dep[f2]?f1:f2;
		}
}
inline int getlca(int u,int v){
	if(dfna[u]>dfna[v])swap(u,v);
	u=dfna[u],v=dfna[v];
	int kk=lg[v-u+1],f1=st[u][kk],f2=st[v-(1<<kk)+1][kk];
	return dep[f1]<dep[f2]?f1:f2;
}
inline int LCA(int x,int y){
	if(x==0||y==0 ) return 0; 
	if(x==y) return x;
	if(dep[x]<dep[y] )swap(x,y);
	Rof(i,20,0){
		if(dep[fa[x][i]]>=dep[y]){
			x=fa[x][i];
		}
	}
	if(x==y) return x;
	Rof(i,20,0){
		if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
	}
	return fa[x][0];
}
int m,a[N];
struct Query{
	int l,r,id;
}z[N];
int kuai,ans[N];
inline bool cmp(Query x,Query y){
	return x.l/kuai==y.l/kuai?((x.l/kuai%2==1)?x.r<y.r:x.r>y.r):x.l<y.l;
}
int tot;
int vis[N];
int f[N];
set<int>s;
int xl[N],xr[N]; 
inline void add(int ppp){
	int x=a[ppp];
	if(in[x]==0)tot++;
	in[x]++;
	int L=id[(*prev(s.upper_bound(dfn[x])))],R=id[*s.upper_bound(dfn[x])];
	int LL=LCA(L,x),RR=LCA(x,R);
	if(LL&&in[LL]==0) tot++; 
	in[LL]+=2;
	if(RR&&in[RR]==0) tot++; 
	in[RR]+=2;
	s.insert(dfn[x]);
//	cout<<"AD"<<a[ppp]<<" "<<tot<<endl;
} 
inline void del(int ppp){
	int x=a[ppp];
	in[x]--;
	if(in[x]==0)tot--;
	s.erase(dfn[x]);
	int L=id[(*prev(s.upper_bound(dfn[x])))],R=id[*s.upper_bound(dfn[x])];
	int LL=LCA(L,x),RR=LCA(x,R);
	in[LL]-=2;
	if(LL&&in[LL]==0) tot--; 
	in[RR]-=2;
	if(RR&&in[RR]==0) tot--; 
//	cout<<"DL"<<a[ppp]<<" "<<tot<<endl;
} 
int gg[N];
inline bool cmb(int x,int y){
	return dfn[x]<dfn[y];
}
signed main(){
	freopen("escape.in","r",stdin);
	freopen("escape.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	n=read();m=read();
	kuai=pow(n,2.0/3);
	For(i,2,n) fa[i][0]=read(),lg[i]=lg[i/2]+1;
	For(i,2,n) q[fa[i][0]].push_back(i),in[i]++,in[fa[i][0]]++;
	bool flag=0; 
	For(i,1,n) if(in[i]>2) flag=1; 
	For(i,1,n) a[i]=read();
	dfs(1,0);buildst();
	For(i,1,m) z[i].l=read(),z[i].r=read(),z[i].id=i;
	if(!flag){
		For(i,1,m){
			printf("%d\n",z[i].r-z[i].l+1);
		}
		return 0;
	}
	For(i,1,m){
		if(z[i].l==z[i].r) {
			puts("1");
			continue;
		}
		tot=0;
		For(j,z[i].l,z[i].r){
			gg[++tot]=a[j];
		}
		sort(gg+1,gg+tot+1,cmb);
		int len=tot;
		For(i,2,len){
			int Lca=getlca(gg[i],gg[i-1]);
			if(Lca!=gg[i]&&Lca!=gg[i-1])
				gg[++tot]=Lca;
		}
		sort(gg+1,gg+tot+1);
		tot=unique(gg+1,gg+tot+1)-gg-1;
		printf("%d\n",tot);
	}
	return 0;
	sort(z+1,z+m+1,cmp);
	int L=1,R=0;
	int cnt=0;
	memset(in,0,sizeof(in));
	s.insert(0);s.insert(n+1);
	For(i,1,m){
		while(L>z[i].l) add(--L);
		while(R<z[i].r) add(++R);
		while(R>z[i].r) del(R--);
		while(L<z[i].l) del(L++);
		ans[z[i].id]=tot;
//		cout<<dfn[z[i].l]<<" "<<z[i].l<<" "<<z[i].r<<endl;
//		for(auto j:s) cout<<id[j]<<" ";
//		puts("");
//		cout<<"VALUE:"<<tot<<endl;
	} 
	For(i,1,m){
		printf("%d\n",ans[i]);
	}
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

